package org.flink.marketing.util;

import java.math.BigDecimal;

/**
 * Created by CaoQing on 2016/4/28.
 */
public class NumberUtil {
    //验证是否是整数
    public boolean isNumber(String str)
    {
        java.util.regex.Pattern pattern=java.util.regex.Pattern.compile("[0-9]*");
        java.util.regex.Matcher match=pattern.matcher(str);
        if(match.matches()==false)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    public static boolean isInteger(String value) {
        try {
            Integer.parseInt(value);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    /**
     * 判断字符串是否是浮点数
     */
    public static boolean isDouble(String value) {
        try {

            BigDecimal.valueOf(Double.parseDouble(value));
            if (value.contains("."))
                return true;
            return false;
        } catch (NumberFormatException e) {
            return false;
        }
    }

    /**
     * 判断字符串是否是数字
     */
    public static boolean issNumber(String value) {
        return isInteger(value) || isDouble(value);
    }
}
